var app = getApp(), Data = require("../../utils/util.js");

Page({
    data: {
        index: 0,
        currentTab: 0,
        swiperCurrent: 0,
        indicatorDots: !1,
        autoplay: !0,
        interval: 5e3,
        duration: 1e3,
        circular: !0,
        averdr: !1,
        hotels: !1,
        refresh_top: !1,
        scroll_top: !0,
        index_class: !1,
        activesxtab: 0,
        goodslist:[],
        tabOrders:0,
        page:1
    },

    onLoad: function() {
        var a = this, t = wx.getStorageSync("city");
        app.setNavigationBarColor(this);
        app.util.request({
            url: "entry/wxapp/Tgz",
            cachetime: "0",
            data: {
                city: t
            },
            success: function(e) {
                if(e.data!=''){
                    
                    a.setData({
                        goodslist: e.data
                    });
                }
                
            }
        }), app.util.request({
            url: "entry/wxapp/System",
            cachetime: "0",
            success: function(e) {
                console.log(e), a.setData({
                    System: e.data
                });
            }
        });
    },
    redinfo: function(t) {
        var e = wx.getStorageSync("users").id;
        app.util.request({
            url: "entry/wxapp/MyDistribution",
            cachetime: "0",
            data: {
                user_id: e
            },
            success: function(t) {
                console.log(t.data), "2" == t.data.state ? (console.log("是推广商"), wx.navigateTo({
                    url: "../distribution/yaoqing"
                })) : "1" == t.data.state ? wx.showModal({
                    title: "提示",
                    content: "您的申请正在审核中，请耐心等待"
                }) : wx.navigateTo({
                    url: "../distribution/jrhhr"
                });
            }
        });
    },
    jumps: function(t) {
        var e = this, a = (t.currentTarget.dataset.name, t.currentTarget.dataset.appid), n = t.currentTarget.dataset.src, i = t.currentTarget.dataset.id, r = t.currentTarget.dataset.sjtype;
        console.log(i);
        var o = t.currentTarget.dataset.type;
        if (1 == o) {
            if (console.log(n), "../distribution/jrhhr" == n) return e.redinfo(), !1;
            wx.navigateTo({
                url: n,
                success: function(t) {
                    e.setData({
                        averdr: !0
                    });
                },
                fail: function(t) {},
                complete: function(t) {}
            });
        } else 2 == o ? wx.navigateTo({
            url: "../car/car?vr=" + i + "&sjtype=" + r,
            success: function(t) {},
            fail: function(t) {},
            complete: function(t) {}
        }) : 3 == o && wx.navigateToMiniProgram({
            appId: a,
            path: "",
            extraData: {
                foo: "bar"
            },
            success: function(t) {
                e.setData({
                    averdr: !0
                });
            }
        });
    },
    choosesort:function(t) {
        var f = t.currentTarget.dataset.taborders,a = this,t = wx.getStorageSync("city");
        if(0 == f){
            app.util.request({
                url: "entry/wxapp/Tgz",
                cachetime: "0",
                data: {
                    order: 'mr',
                    city:t
                },
                success: function(e) {
                     a.setData({
                        tabOrders:0,
                        page:1,
                        goodslist:e.data
                    }) ;
                }
            });
          
        }else if(1 == f){
            app.util.request({
                url: "entry/wxapp/Tgz",
                cachetime: "0",
                data: {
                    order: 'zx',
                    city:t
                },
                success: function(e) {
                    a.setData({
                        tabOrders:1,
                        page:1,
                        goodslist:e.data
                    });
                }
            });
        } 
        if(2 == a.data.tabOrders && 2 == f){
            app.util.request({
                url: "entry/wxapp/Tgz",
                cachetime: "0",
                data: {
                    order: 'yjx',
                    city:t
                },
                success: function(e) {
                   a.setData({
                        tabOrders:3,
                        page:1,
                        goodslist:e.data
                    });
                }
            });
        }else if(2== f){
            app.util.request({
                url: "entry/wxapp/Tgz",
                cachetime: "0",
                data: {
                    order: 'yjs',
                    city:t
                },
                success: function(e) {
                    a.setData({
                        tabOrders:2,
                        page:1,
                        goodslist:e.data
                    });
                }
            });
        } 
        if(4 == a.data.tabOrders && 4 == f){
            app.util.request({
                url: "entry/wxapp/Tgz",
                cachetime: "0",
                data: {
                    order: 'xlx',
                    city:t
                },
                success: function(e) {
                    a.setData({
                        tabOrders:5,
                        page:1,
                        goodslist:e.data
                    });
                }
            });
        }else if(4 == f){
            app.util.request({
                url: "entry/wxapp/Tgz",
                cachetime: "0",
                data: {
                    order: 'xls',
                    city:t
                },
                success: function(e) {
                    a.setData({
                        tabOrders:4,
                        page:1,
                        goodslist:e.data
                    });
                }
            });
        }  
        
        if(3 == a.data.tabOrders && 3 == f){
            app.util.request({
                url: "entry/wxapp/Tgz",
                cachetime: "0",
                data: {
                    order: 'yjs',
                    city:t
                },
                success: function(e) {
                   a.setData({
                        tabOrders:2,
                        page:1,
                        goodslist:e.data
                    });
                }
            });
        }else if(5 == a.data.tabOrders && 5 == f){
            app.util.request({
                url: "entry/wxapp/Tgz",
                cachetime: "0",
                data: {
                    order: 'xls',
                    city:t
                },
                success: function(e) {
                    a.setData({
                        tabOrders:4,
                        page:1,
                        goodslist:e.data
                    });
                }
            });
        }
    },
    store_info: function(t) {
        var e = t.currentTarget.id;
        var f = t.currentTarget.dataset.store_id;
        
        wx.navigateTo({
            url: "../sellerinfo/good_info?id=" + e + "&store_id="+ f,
           
            success: function(t) {},
            fail: function(t) {},
            complete: function(t) {}
        });
    },
    lower: function(t) {
        var a = this,page = parseInt(this.data.page)+1,c = wx.getStorageSync("city"),u = this.data.goodslist,od = a.data.tabOrders;

        if(0 == od){
            var o = 'mr';
        }else if(1 == od){
            var o = 'zx'
        }else if(2 == od){
            var o = 'yjs'
        }else if(3 == od){
            var o = 'yjx'
        }else if(4 == od){
            var o = 'xls'
        }else if(5 == od){
            var o = 'xlx'
        }
        app.util.request({
            url: "entry/wxapp/Tgz",
            cachetime: "0",
            data: {
                page: page,
                city:c,
                order:o
            },
            success: function(e) {
                a.setData({
                    page:page+1,
                    tabOrders:od
                }),u = u.concat(e.data),a.setData({
                    goodslist:u   
                });
            }
        });
    },
    onReady: function() {},

    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
   
});